#include "sCRText.h"
#include "sCRIText.h"

namespace sgui
{
namespace res
{

const std::wstring& sComponentRectText::getText() const
{
	return m_text;
}

void sComponentRectText::setText(const std::wstring& name)
{
	m_text = name;
}

inst::sComponentRectInstance* sComponentRectText::getInstance(inst::sComponentInstance& instanceFor, s32 id) const
{
	return new inst::sComponentRectText(*this, instanceFor, id);
}

const bool& sComponentRectText::getWordWrap() const
{
	return m_wordWrap;
}

void sComponentRectText::setWordWrap(const bool& wordWrap)
{
	m_wordWrap = wordWrap;
}

void sComponentRectText::save(db::Record& file) const
{
	sComponentRect::save(file);

	file[L"text"].Set(m_text);
	file[L"word_wrap"].Set(getWordWrap());
    file[L"valign"].Set((u32)m_verticalAlign);
    file[L"halign"].Set((u32)m_horisontalAlign);
}

void sComponentRectText::load(const db::Record& file)
{
	sComponentRect::load(file);
	
	m_text = file[L"text"].GetAsString();
	setWordWrap(file[L"word_wrap"].GetAsBool());
    m_verticalAlign = (EVerticalFontAlign)file[L"valign"].GetAsInt();
    m_horisontalAlign = (EHorisontalFontAlign)file[L"halign"].GetAsInt();
}

void sComponentRectText::clear()
{
	sComponentRect::clear();

	setText(L"");
	m_wordWrap = true;
    m_verticalAlign = VFA_MIDDLE;
    m_horisontalAlign = HFA_CENTER;
}
		
preset::sGroup<preset::sFontPreset>& sComponentRectText::getFontPresetGroup()
{
	return m_fontPreset;
}	

const preset::sGroup<preset::sFontPreset>& sComponentRectText::getFontPresetGroup() const
{
	return m_fontPreset;
}
		
sComponentRectText::sComponentRectText(sGUI& gui) :
	sComponentRect(gui),
	m_fontPreset(gui),
	m_wordWrap(true),
    m_verticalAlign(VFA_MIDDLE), 
    m_horisontalAlign(HFA_CENTER)
{

}
	
#ifdef _EDITOR
void sComponentRectText::exportRTTI(rtti::sInfoList& list)
{
	sComponentRect::exportRTTI(list);
	REGISTER_RTTI(L"Text", TEXT, NEW_RTTI_PARAMETER(
		STRING, sComponentRectText, this, &sComponentRectText::setText, &sComponentRectText::getText
	));
    REGISTER_RTTI(L"Word wrap", TEXT, NEW_RTTI_PARAMETER(
		BOOL, sComponentRectText, this,  &sComponentRectText::setWordWrap, &sComponentRectText::getWordWrap
	));
	REGISTER_RTTI(L"Vertival align", TEXT, NEW_RTTI_TEMPLATE_PARAMETER(
		ENUM, EVerticalFontAlign, sComponentRectText, this, &sComponentRectText::setVerticalAlign, &sComponentRectText::getVerticalAlign
	));
	REGISTER_RTTI(L"Horisontal align", TEXT, NEW_RTTI_TEMPLATE_PARAMETER(
		ENUM, EHorisontalFontAlign, sComponentRectText, this, &sComponentRectText::setHorisontalAlign, &sComponentRectText::getHorisontalAlign
	));
}
#endif

};
};